package com.sxkj.web.controller.sys;

import com.sxkj.common.response.ResponseResult;
import com.sxkj.entity.base.Page;
import com.sxkj.entity.entity.sys.Menu;
import com.sxkj.service.sys.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *
 * @title: MenuController
 * @author: daixiaowei
 * @date: 2019年12月17日 下午 02:47:17
 * @description: 菜单接口
 */
@Controller
@Api(tags = "MenuController", description = "菜单接口")
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     *
     * @title: searchListPage
     * @author: daixiaowei
     * @date: 2019年12月17日 下午 02:49:07
     * @description: 查询菜单列表
     * @param: menu pageSize pageNum
     * @return:
     */
    @ApiOperation(value = "查询菜单列表")
    @RequestMapping(value = "/searchListPage", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult searchListPage(@RequestParam(value =
            "pageSize",
            defaultValue = "10") Integer pageSize, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return ResponseResult.success(Page.restPage(menuService.searchListPage(pageSize, pageNum)));
    }

    /**
     *
     * @title: addMenu
     * @author: daixiaowei
     * @date: 2019年12月18日 下午 04:55:59
     * @description: 菜单新增
     * @param: menu
     * @return:
     */
    @ApiOperation(value = "菜单新增")
    @RequestMapping(value = "/addMenu", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult addMenu(@RequestBody Menu menu, BindingResult result) {
        menuService.add(menu);
        return ResponseResult.success();
    }

    /**
     *
     * @title: updateMenu
     * @author: daixiaowei
     * @date: 2019年12月18日 下午 04:59:25
     * @description: 菜单修改
     * @param: menu
     * @return:
     */
    @ApiOperation(value = "菜单修改")
    @RequestMapping(value = "/updateMenu", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult updateMenu(@RequestBody Menu menu, BindingResult result) {
        menuService.update(menu);
        return ResponseResult.success();
    }

    /**
     *
     * @title: search
     * @author: daixiaowei
     * @date: 2019年12月18日 下午 05:20:31
     * @description: 查询menu
     * @param: id
     * @return:
     */
    @ApiOperation(value = "查询menu")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult search(@RequestParam(value = "id") String id) {
        return ResponseResult.success(menuService.searchMenuById(id));
    }

    /**
     *
     * @title: deleteMenu
     * @author: daixiaowei
     * @date: 2019年12月18日 下午 05:51:10
     * @description: 根据id删除
     * @param: menu
     * @return:
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/deleteMenu", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteMenu(@RequestBody Menu menu, BindingResult result) {
        menuService.deleteMenuById(menu.getId());
        return ResponseResult.success();
    }

    /**
     *
     * @title: reloadMenuTree
     * @author: daixiaowei
     * @date: 2019年12月24日 上午 11:53:24
     * @description: 重新加载MenuTree
     * @param:
     * @return:
     */
    @ApiOperation(value = "重新加载MenuTree")
    @RequestMapping(value = "/reloadMenuTree", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult reloadMenuTree() {
        return ResponseResult.success(menuService.reloadMenuTree());
    }

}
